pythons os module choose random file

57

pythons os module choose random file -

import os
import random
import dircache

dir = 'some/directory'
filename = random.choice(dircache.listdir(dir))
path = os.path.join(dir, filename)

Comments

Submit
0 Comments